package com.freecloud.javabasics.design.observer.subject;

import com.freecloud.common.LoggerUtil;
import com.freecloud.javabasics.design.observer.Event;

import java.lang.reflect.Method;

/**
 * 观察者模式
 * @Author: maomao
 * @Date: 2019-11-19 09:44
 */
public class ObserverTest {
    public static void main(String[] args) {
        try {


            //被观察者
            Subject subject = new Subject();
            Method advice = Observer.class.getMethod("advice",new Class<?>[]{Event.class});


            //观察者
            Observer observer = new Observer();
            //注册观察者
            subject.addLisenter(SubjectEventType.ON_ADD,observer,advice);
            subject.addLisenter(SubjectEventType.ON_DELETE,observer,advice);
            LoggerUtil.printThread();

            subject.add();
            subject.delete();
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
